package com.ejd.web.vo.genl;

import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import com.ejd.service.ILoginLogService;
import com.ejd.service.ISizeService;
import com.ejd.service.impl.LoginLogService;
import com.ejd.utils.DateTimeUtil;
import com.ejd.utils.SpringFacesUtil;
import com.ejd.web.bo.impl.LoginLog;
import com.ejd.web.bo.impl.Size;
import com.ejd.web.constant.ManageBeanConstants;
import com.ejd.web.constant.SpringBeanConstants;
import com.ejd.web.vo.customer.LoginCustomerPageBean;
@ManagedBean(name="loginLog")
@SessionScoped
public class LoginLogBean implements java.io.Serializable {

	private static final long serialVersionUID = -8106629465344224746L;
	private LoginLog loginLog;
	
	public LoginLogBean() {
		LoginLog loginLog = new LoginLog();
		loginLog.setIp(SpringFacesUtil.getIpAddress());
		loginLog.setLoginTime(DateTimeUtil.getCurrentTimestamp());
		
		LoginCustomerPageBean loginCustomerPage = (LoginCustomerPageBean) SpringFacesUtil.getManagedBean(ManageBeanConstants.LOGIN_CUSTOMER_PAGE_BEAN_NAME);
		String customerId = null;
		if (null != loginCustomerPage && null != loginCustomerPage.getCustomerInfo()) {
			customerId = loginCustomerPage.getCustomerInfo().getCustomerId();
		}
		loginLog.setCustomerId(customerId);
		ILoginLogService<LoginLog,Long> loginLogService = (ILoginLogService<LoginLog,Long>)SpringFacesUtil.getSpringBean(SpringBeanConstants.LOGIN_LOG_SERVICE_BEAN_NAME);
		loginLogService.setEntityClass(LoginLog.class);
		loginLogService.setPKClass(Long.class);
		loginLogService.save(loginLog);
		this.setLoginLog(loginLog);
	}

	public LoginLog getLoginLog() {
		return loginLog;
	}

	public void setLoginLog(LoginLog loginLog) {
		this.loginLog = loginLog;
	}
	
}
